const arr = [1, 4, 2, 3, 5]
function bubbleSort(arr) {
    console.log(`bubbling bubbling bubbling`)
    for (let i = 0; i < arr.length - 1; i++) {
        let swapped = false
        for (let j = 0; j < arr.length - i - 1; j++) {
            if (arr[j] > arr[j + 1]) {
                [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]]
                swapped = true
            }
        }
        if (!swapped) {
            break
        }
    }
}

console.log(`排序前输出数组${arr}`)
bubbleSort(arr)
console.log(`排序后输出数组${arr}`)

